package com.aizhixin.lab.statistics.controller;

import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.account.service.AccountService;
import com.aizhixin.lab.common.utils.TokenUtil;
import com.aizhixin.lab.project.template.domain.WorkOrderDomain;
import com.aizhixin.lab.statistics.domain.*;
import com.aizhixin.lab.statistics.service.AdminService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/statistics/admin")
@Api(value = "管理端数据Api", description = "管理端数据Api")
public class AdminDataController {
    @Autowired
    private AdminService adminService;
    @Autowired
    private AccountService accountService;


    @RequestMapping(value = "/getCourserData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "POST", value = "获取课程数据", response = Void.class, notes = "获取课程数据<br>@author lwq")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = CourseDataDomain.class),})
    public ResponseEntity<?> getCourserData(@RequestHeader("Authorization") String token,
                                            @RequestBody QueryCourseDomain domain) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        CourseDataDomain data = adminService.getData(domain);
        return new ResponseEntity(data, HttpStatus.OK);
    }
    @RequestMapping(value = "/getCourserList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "POST", value = "获取课程引入列表", response = Void.class, notes = "获取课程引入列表<br>@author lwq")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = GiveLessonsDomain.class),})
    public ResponseEntity<?> getCourserList(@RequestHeader("Authorization") String token,
                                          @RequestBody QueryCourseDomain domain) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        Map<String, Object> list = adminService.getList(domain);
        return new ResponseEntity(list, HttpStatus.OK);
    }
    @RequestMapping(value = "/getProjectList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "POST", value = "获取项目引入列表", response = Void.class, notes = "获取项目引入列表<br>@author lwq")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ProjectGiveLessonsDomain.class),})
    public ResponseEntity<?> getProjectList(@RequestHeader("Authorization") String token,
                                            @RequestBody QueryProjectDomain domain) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        Map<String, Object> list = adminService.getProjectList(domain);
        return new ResponseEntity(list, HttpStatus.OK);
    }
    @RequestMapping(value = "/getProjectData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "POST", value = "获取项目数据", response = Void.class, notes = "获取项目数据<br>@author lwq")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ProjectDataDomain.class),})
    public ResponseEntity<?> getProjectData(@RequestHeader("Authorization") String token,
                                            @RequestBody QueryProjectDomain domain) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        ProjectDataDomain data = adminService.getProjectData(domain);
        return new ResponseEntity(data, HttpStatus.OK);
    }
    @RequestMapping(value = "/getCourseTemplateData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "POST", value = "获取课程模板使用数据", response = Void.class, notes = "获取课程模板使用数据<br>@author lwq")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ProjectDataDomain.class),})
    public ResponseEntity<?> getCourseTemplateData(@RequestHeader("Authorization") String token,
                                            @RequestBody QueryCourseDomain domain) {
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        Map<String, Object> course = adminService.getCourse(domain);
        return new ResponseEntity(course, HttpStatus.OK);
    }
}
